<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body id="body">
    <input type="text" name="" id="row">
    <input type="text" name="" id="col">
    <button id="btn">确定</button>
    <table id="table" border="1"></table>
    <script>
        //生成表格
        // var body = document.getElementById('body')
        let table = document.getElementById('table')
        var row = document.getElementById('row')
        var col = document.getElementById('col')
        var btn = document.getElementById('btn')
        // console.log(btn)
        btn.onclick = function () {
            // var table = '<table border="1">'
            var tableinner=''
            rowv = row.value
            colv = col.value
            for (var i = 0; i < rowv; i++) {
                tableinner += '<tr>'
                for (var j = 0; j < colv; j++) {
                    tableinner += '<td>' + (i + 1) + '-' + (j + 1) + '</td>'
                }
                tableinner += '</tr>'
            }
            // table += '</table>'
            console.log(tableinner)
            table.innerHTML = tableinner
            // console.log(btn)
            // body.innerHTML+=document.write(table)
        }
    </script>
</body>

</html>